from concurrent.futures import ThreadPoolExecutor,as_completed,wait
import time

def get_html(url):
    time.sleep(url)
    print("get html success")

    return url


if __name__ == '__main__':
    with ThreadPoolExecutor(max_workers=2) as executor:
        urls=[2,2,3,4,2]

        # 获取执行结果 方式1
        all_task=[executor.submit(get_html,(url)) for url in urls]
        # for future in as_completed(all_task):
        #     print(">>>>>{}".format(future.result()))

        #获取执行结果 方式2
        # for data in executor.map(get_html,urls):
        #     print("2>>>>>{}".format(data))

        # 等待所有task执行完成，阻塞主线程
        wait(all_task)